package com.joysuch.wwyt.workflow.controller;


import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.workflow.bean.*;
import com.joysuch.wwyt.workflow.entity.WorkFlowOption;
import com.joysuch.wwyt.workflow.entity.WorkFlowOptionType;
import com.joysuch.wwyt.workflow.service.WorkFlowOptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/workflow-option")
@Api(tags = "业务流程-选项配置管理")
@CrossOrigin
public class WorkFlowOptionController {



    @Autowired
    private WorkFlowOptionService workFlowOptionService;



    @GetMapping("/getOptionList")
    @ApiOperation(value = "获取选项内容列表(根据类型名称）" , response = WorkFlowOption.class)
    public ResultBean getOptionList(String optionName) {
       List<WorkFlowOption> list = workFlowOptionService.getOptionList(optionName);
       return ResultBean.success(list);
    }


    @GetMapping("/getOptionListById")
    @ApiOperation(value = "获取选项内容列表(根据类型Id）" , response = WorkFlowOption.class)
    public ResultBean getOptionListById(Long typeId) {
        List<WorkFlowOption>  list = workFlowOptionService.getOptionList(typeId);
        return ResultBean.success(list);
    }


    @GetMapping("/getOptionTypeList")
    @ApiOperation(value = "获取选项类型列表" , response = WorkFlowOptionType.class)
    public ResultBean getOptionTypeList() {
        List<WorkFlowOptionType>  list = workFlowOptionService.getOptionTypeList();
        return ResultBean.success(list);
    }

    @GetMapping("/pageOptionType")
    @ApiOperation(value = "分页选项类型" )
    public ResultBean pageOptionType(Pageable page,String optionType) {
       return workFlowOptionService.pageOptionType(page,optionType);
    }

    @RequiresPermissions("workflow:option:type:save")
    @PostMapping("/saveOptionType")
    @ApiOperation(value = "保存" , response = WorkFlowOptionType.class)
    public ResultBean saveOptionType(@RequestBody WorkFlowOptionTypeBean bean) {
        WorkFlowOptionType workFlowOptionType = workFlowOptionService.saveOptionType(bean);
        return ResultBean.success(workFlowOptionType);

    }

    @RequiresPermissions("workflow:option:save")
    @PostMapping("/addOptions")
    @ApiOperation(value = "批量新增")
    public ResultBean addOptions(@RequestBody List<WorkFlowOptionBean> workFlowOptionBeans, Long optionType) {
        return workFlowOptionService.addOptions(workFlowOptionBeans, optionType);
    }

    @RequiresPermissions("workflow:option:save")
    @PostMapping("/saveOption")
    @ApiOperation(value = "保存" , response = WorkFlowOptionType.class)
    public ResultBean saveOption(@RequestBody WorkFlowOptionBean workFlowOptionBean) {
        WorkFlowOption workFlowOption = workFlowOptionService.saveOption(workFlowOptionBean);
        return ResultBean.success(workFlowOption);

    }


    @GetMapping("/getOptionType/{id}")
    @ApiOperation(value = "获取详情", response = WorkFlowOptionType.class)
    @ApiImplicitParam(name = "id", value = "选项类型ID", paramType = "path", required = true)
    public ResultBean getOptionType(@PathVariable Long id){
        WorkFlowOptionType workFlowOptionType = workFlowOptionService.getOptionType(id);
        return ResultBean.success(workFlowOptionType);

    }


    @GetMapping("/getOption/{id}")
    @ApiOperation(value = "获取详情", response = WorkFlowOption.class)
    @ApiImplicitParam(name = "id", value = "选项ID", paramType = "path", required = true)
    public ResultBean getOption(@PathVariable Long id){
        WorkFlowOption workFlowOption = workFlowOptionService.getOption(id);
        return ResultBean.success(workFlowOption);

    }

    @RequiresPermissions("workflow:option:type:delete")
    @GetMapping("/deleteOptionType/{id}")
    @ApiOperation(value = "删除", response = WorkFlowOptionType.class)
    @ApiImplicitParam(name = "id", value = "选项类型ID", paramType = "path", required = true)
    public ResultBean deleteOptionType(@PathVariable Long id){
        workFlowOptionService.deleteOptionType(id);
        return ResultBean.defaultSuccessResult();

    }

    @RequiresPermissions("workflow:option:delete")
    @GetMapping("/deleteOption/{id}")
    @ApiOperation(value = "删除", response = WorkFlowOption.class)
    @ApiImplicitParam(name = "id", value = "选项ID", paramType = "path", required = true)
    public ResultBean deleteOption(@PathVariable Long id){
        workFlowOptionService.deleteOption(id);
        return ResultBean.defaultSuccessResult();

    }



}
